﻿using SCADA_SANEST.Helpers;
using SCADA_SANEST.Models;
using SCADA_SANEST.Services;
using SCADA_SANEST.Services.Line_4;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace SCADA_SANEST.ViewModels.Line_4
{
    public class Hbt4ViewModel : BaseViewModel
    {
        public ObservableCollection<PlcSignal> Signals { get; }
        public RelayCommand<object> ShowPlcDetailCommand { get; }

        public Hbt4ViewModel(PlcDeviceStatus backend)
        {
            // Lấy service đã tồn tại hoặc tạo mới
            var service = ServiceManager.GetOrRegisterService("HBT4", new Hbt4Service(backend));

            Signals = service.Signals;

            ShowPlcDetailCommand = new RelayCommand<object>(
                _ => true,
                _ => ShowPlcDetail()
            );
        }

        private void ShowPlcDetail()
        {
            var detailControl = new Views.Common.PlcDataDetail
            {
                DataContext = this // dùng cùng Signals
            };

            var window = new Window
            {
                Title = "Chi tiết PLC",
                Content = detailControl,
                Width = 600,
                Height = 400
            };

            window.Show();
        }
    }
}
